package com.gsdse.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gsdse.pojo.Department;
import com.gsdse.pojo.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public interface DepartmentDao extends BaseMapper<Department> {

    @Select("select * from department where departmentId=#{departmentId}")
    Department selectDepartmentById (Integer departmentId);



    @Update("update department set applyNumber=#{applyNumber}, identification=#{identification}, " +
            "departmentKey=#{departmentKey}, notice=#{notice}, congratulation=#{congratulation} where departmentId=#{departmentId}")
    Boolean updateDepartmentById(Department department);

    //查询部门成员
    @Select("select user.userId,user.applyId,user.phoneNumber,user.userName,user.schoolClass,user.email,user.positionName,user.position,user.wxuserId,user.departmentId,wxuser.avatarUrl,wxuser.nickName from user,wxuser where user.departmentId=#{departmentId} and user.userId=wxuser.userId limit #{start},#{pageSize} ")
    List<User> selectMembers(@Param("departmentId") Integer departmentId, @Param("start") int start, @Param("pageSize") Integer pageSize);

    @Select("select count(*) from user where departmentId=#{departmentId}")
    //查询部门成员数量
    int selectMemberCount(@Param("departmentId") Integer departmentId);

    @Update("update  user set positionName=0,position='无',departmentId=0 where userId=#{userId}")
    boolean removeUser(@Param("userId") Integer userId);
}
